﻿namespace ETestIT.UI
{
    using System;
    using System.Web.UI.WebControls;
    using Core;
    using Core.Infrastructure;
    using Core.Services;
    using Presentation;
    using Presentation.Storage;
    using SharpArch.Core.PersistenceSupport;

    public partial class ResumeHistory : PageBase<ResumeHistory>
    {
        ICandidateResumeService candidateResumeService;
        IRepository<Resume> resumeRepository;
        ISessionProvider sessionStorage;

        protected void Page_Load(object sender, EventArgs e)
        {
            resumeRepository = IoC.Resolve<IRepository<Resume>>();
            sessionStorage = IoC.Resolve<ISessionProvider>();
            candidateResumeService = IoC.Resolve<ICandidateResumeService>();

            if (IsPostBack) 
                return;

            var candidateResumeId = sessionStorage.Get<int>(Const.SelectedCandidateResumeKey);

            gvReumes.DataSource = candidateResumeService.GetHistoryByCanditadeResumeId(candidateResumeId);
            gvReumes.DataBind();
        }

        protected void LnkResumesViewCommand(object sender, CommandEventArgs e)
        {
            var resumeId = int.Parse(e.CommandArgument.ToString());
            var resume = resumeRepository.Get(resumeId);
            Response.WriteResumeToResponse(resume);
        }
    }
}